home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / MATHS / RLAB / RLAB125.ZIP / !RLaB / toolbox / mdsmooth < prev    next >
Text File  |  1995-03-20  |  1KB  |  58 lines

  1. %MDSMOOTH Median smoothing filter.
  2.  
  3. %       [y] = MDSMOOTH(X,L) smooths the input vector X using a
  4. %       median filter with a rectangular window of "L" samples.
  5. %
  6. %       See also: SP_STENG, SP_STMAG, SP_STZCR, AVSMOOTH
  7. %
  8. %       MDSMOOTH is implemented as a mex function on some
  9. %       installations.
  10.  
  11. %       Matlab original by:
  12. %       LT Dennis W. Brown 7-11-93, DWB 8-17-93
  13. %       Naval Postgraduate School, Monterey, CA
  14. %       May be freely distributed.
  15. %       Not for use in commercial products.
  16.  
  17. require median
  18.  
  19. mdsmooth = function ( x , L )
  20. {
  21.   local ( x , L )
  22.  
  23.   % default output
  24.   y = [];
  25.  
  26.   % check args
  27.   if (nargs != 2)
  28.   {
  29.     error("mdsmooth: Invalid number of input arguments...");
  30.   }
  31.  
  32.   % figure out if we have a vector
  33.   if (min(size(x)) != 1)
  34.   {
  35.     error("mdsmooth: Input arg \"x\" must be a 1xN or Nx1 vector.");
  36.   }
  37.  
  38.   % work with Nx1 vectors
  39.   x = x[:];
  40.  
  41.   % number of samples
  42.   Ns = length(x);
  43.   
  44.   % room for output
  45.   y = zeros(Ns,1);
  46.  
  47.   % pad ends to compensate for filter length
  48.   x = [zeros(L/2-1,1); x ; 0 ; zeros(L/2,1)];
  49.  
  50.   % median filter
  51.   for (k in 1:Ns)
  52.   {
  53.     y[k;1] = median(x[k:k+L-1;1]);
  54.   }
  55.  
  56.   return y;
  57. };
  58.